// -----------------------------------------------------------------------
// <copyright file="CoordinationEN.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Data.SqlClient;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    
    /// <summary>
    /// Class Coordination
    /// </summary>
    public class CoordinationEN : EntityEN
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CoordinationEN" /> class
        /// </summary>
        public CoordinationEN()
        {
            this.CoordinationId = 0;
            this.CoordinationUserId = 0;
            this.WorkflowProfileId = 0;
            this.Role = string.Empty;
            this.RW = false;
        }
        
        /// <summary>
        /// Gets or sets CoordinationId
        /// </summary>
        public int CoordinationId { get; set; }
        
        /// <summary>
        /// Gets or sets CoordinationUserId
        /// </summary>
        public int CoordinationUserId { get; set; }
        
        /// <summary>
        /// Gets or sets WorkflowProfileId
        /// </summary>
        public int WorkflowProfileId { get; set; }
        
        /// <summary>
        /// Gets or sets Role
        /// </summary>
        public string Role { get; set; }
        
        /// <summary>
        /// Gets or sets a value indicating whether the item is RW
        /// </summary>
        public bool RW { get; set; }

        /// <summary>
        /// Gets User
        /// </summary>
        public UserEN CoordinationUser
        {
            get
            {
                try
                {
                    UserEN user = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneUsersGetById, this.CoordinationUserId);

                    while (reader.Read())
                    {
                        user = new UserEN();

                        if (!reader.IsDBNull(0))
                        {
                            user.UserId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            user.AdministrativeUnitsId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            user.UserName = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            user.FullName = reader.GetString(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            user.Sex = reader.GetBoolean(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            user.BirthDate = reader.GetDateTime(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            user.Email = reader.GetString(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            user.Sms = reader.GetString(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            user.Phone = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            user.Address = reader.GetString(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            user.CreateDate = reader.GetDateTime(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            user.Send = reader.GetString(11);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return user;
                }
                catch (SqlException ex)
                {
                    LogHelper.Instance.WriteError(ex);
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets WorkflowProfile
        /// </summary>
        public WorkflowProfileEN WorkflowProfile
        {
            get
            {
                try
                {
                    WorkflowProfileEN workflowProfile = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneWorkflowProfileGetById, this.WorkflowProfileId);

                    while (reader.Read())
                    {
                        workflowProfile = new WorkflowProfileEN();

                        if (!reader.IsDBNull(0))
                        {
                            workflowProfile.WorkflowProfileId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            workflowProfile.ProfileId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            workflowProfile.WorkflowId = reader.GetInt32(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            workflowProfile.NodeId = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            workflowProfile.SendUserId = reader.GetInt32(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            workflowProfile.MainUserId = reader.GetInt32(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            workflowProfile.ProgressWorkId = reader.GetInt32(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            workflowProfile.IsCurrent = reader.GetBoolean(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            workflowProfile.StartDate = reader.GetDateTime(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            workflowProfile.EndDate = reader.GetDateTime(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            workflowProfile.Role = reader.GetString(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            workflowProfile.RW = reader.GetBoolean(11);
                        }

                        if (!reader.IsDBNull(12))
                        {
                            workflowProfile.SendDepartmentId = reader.GetInt32(12);
                        }

                        if (!reader.IsDBNull(13))
                        {
                            workflowProfile.MainDepartmentId = reader.GetInt32(13);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return workflowProfile;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
